package operation.impl;

import book.Book;
import book.BookList;
import operation.IOperation;

import java.util.Scanner;

/**
 * 删除图书
 */
public class DelOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入要删除的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                if(book.isBorrowed()){
                    System.out.println("您要删除的图书正在被借阅中，请等图书归还后再删除！");
                    return;
                }
                //将要删除的图书置为空即可，并不是真的从图书列表中删除
                bookList.setBook(i,null);
                System.out.println("删除图书成功！");
                return;
            }
        }
        System.out.println("不好意思，没有找到您要删除的图书。");
    }
}
